<template>
	<view class="message">
		<view class="head" :style="{height: pHeight + tHeight + 'px'}">
			<view class="xztitle" :style="[{height: pHeight + 'px', top: tHeight + 'px',lineHeight: pHeight + 'px'}]">
				员工管理
				<view class="iconfont icon-dayuhao1" @click="fanhui"></view>
			</view>
		</view>
		<view class="headtop" :style="{marginTop: pHeight + tHeight + 'px'}">
			<view class="top clearfix">
				<view class="left fl clearfix">
					<view class="mess fl" @click="qiehuan(1)">
						<view :class="[attrIndex==1?'active':'']">直营员工</view>
						<text class="dian" v-if="attrIndex == 1"></text>
					</view>
					<view class="mess mess1 fl" @click="qiehuan(2)" v-if="role_id == 1">
						<view :class="[attrIndex==2?'active':'']">团队员工</view>
						<text class="dian" v-if="attrIndex == 2"></text>
					</view>
				</view>
				<view class="right fr clearfix" @click="showstatus = true">
					<image :src="baseUrl + '/wximage/shaixuan.png'" class="fl"></image>
					<view class="name fl">筛选</view>
					<u-select v-model="showstatus" :list="timelist" @confirm="confirm"></u-select>
				</view>
				<view class="right rightts fr clearfix" @click="topage('/subpackageA/staff/add')">
					<image :src="baseUrl + '/wximage/add.png'" class="fl"></image>
					<view class="name fl">新增</view>
				</view>
			</view>
			<view class="sousuo clearfix">
				<input type="text" placeholder="请输入关键字" v-model="keywords" @confirm="sousuo" />
				<image :src="baseUrl + '/wximage/sousuo.png'" @click="sousuo"></image>
			</view>
		</view>
		<view class="content" v-if="list.length != 0">
			<view class="list" v-for="(item,index) in list" :key="index">
				<view class="top clearfix">
					<image :src="baseUrl + '/wximage/shanghugl.png'" class="fl"></image>
					<view class="title fl">{{item.nickname}}</view>
					<view class="money fr">已关联商户：{{item.shanghucount}}</view>
				</view>
				<view class="center clearfix">
					<view class="desc fl">员工联系人：{{item.lxrname}}</view>
					<view class="descid fr">员工ID：{{item.id}}</view>
				</view>
				<view class="tongji clearfix">
					<view class="liebiao fl">
						<view class="money">{{item.dyshouyi}}</view>
						<view class="name">当月收益(元)</view>
					</view>
					<view class="liebiao fl">
						<view class="money">{{item.ljshouyi}}</view>
						<view class="name">累计收益(元)</view>
					</view>
				</view>
				<view class="bottom">
					<view class="li" @click="topage('/subpackageA/staff/all?staff_id=' + item.id)">查看设备</view>
					<view class="li" @click="topage('/subpackageA/staff/detail?staff_id=' + item.id)">更多<view class="xian"></view>
					</view>
				</view>
			</view>
		</view>
		<view class="empty" v-else>
			<image :src="baseUrl + '/wximage/empty.png'"></image>
			<text>暂无相关数据</text>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				baseUrl: getApp().globalData.baseUrl,
				headerTop: 0,
				pHeight: 0,
				tHeight: 0,
				attrIndex: 1,
				showstatus: false,
				timelist: [{
					value: '0',
					label: '全部',
				}, {
					value: '1',
					label: '合作中',
				}, {
					value: '2',
					label: '合作结束',
				}],
				value: '',
				keywords: '',
				role_id: uni.getStorageSync('role_id'),
				list: [],
				page: 1,
				pageSize: 10,
				total: 0,
			}
		},
		onLoad() {
			// 头部距离
			let res = uni.getSystemInfoSync() ///微信api方法
			let titleH;
			if (res && res['system']) {
				// 判断是否是安卓操作系统 （标题栏苹果为44px,安卓为48px）
				if (res['system'].indexOf('Android') > 0) {
					titleH = 48
				} else {
					titleH = 46
				}
				this.headerTop = titleH + res['statusBarHeight']
				this.pHeight = titleH
				this.tHeight = res['statusBarHeight']
			}
		},
		onShow() {
			this.total = 0;
			this.page = 1;
			this.list = [];
			this.getList(this.attrIndex, this.keywords, this.value, this.page, this.pageSize);
		},
		onReachBottom() {
			if (this.total != this.list.length) {
				this.page = this.page + 1;
		
				this.getList(this.attrIndex, this.keywords, this.value, this.page, this.pageSize);
			}
		},
		methods: {
			getList(attrIndex, keywords, value, page, pageSize) {
				this.request({
					url: '/xcx/stafflist',
					data: {
						agent_id: uni.getStorageSync('agent_id'),
						role_id: uni.getStorageSync('role_id'),
						attrIndex: attrIndex,
						keywords: keywords,
						value: value,
						page: page,
						pageSize: pageSize,
					},
					method: "POST"
				}).then(res => {
					if (res.data.code == 200) {
						this.total = res.data.data.total;
						this.list = this.list.concat(res.data.data.data);
					} else {
						uni.showToast({
							title: '请求失败，请稍后再试',
							icon: 'none'
						})
					}
				})
			},
			qiehuan(index){
				this.attrIndex = index;
				
				this.keywords = '';
				this.total = 0;
				this.page = 1;
				this.list = [];
				this.getList(this.attrIndex, this.keywords, this.value, this.page, this.pageSize);
			},
			confirm(e) {
				this.value = e[0].value;
				
				this.total = 0;
				this.page = 1;
				this.list = [];
				this.getList(this.attrIndex, this.keywords, this.value, this.page, this.pageSize);
			},
			sousuo(){
				this.total = 0;
				this.page = 1;
				this.list = [];
				
				this.getList(this.attrIndex, this.keywords, this.value, this.page, this.pageSize);
			},
			fanhui() {
				uni.navigateBack();
			},
			topage(url) {
				uni.navigateTo({
					url
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.message {
		width: 100%;
		margin: 0 auto;
		height: 100vh;
		background: #f9f9ff;
		overflow-y: scroll;

		.head {
			width: 100%;
			position: fixed;
			top: 0;
			left: 0;
			z-index: 99;
			background: linear-gradient(90deg, #f9f9ff, #d4e8ff);

			.xztitle {
				position: fixed;
				left: 0%;
				top: 0;
				width: 100%;
				text-align: left;
				color: #333333;
				font-size: 32rpx;
				padding-left: 74rpx;
				font-weight: 700;

				text {
					font-size: 24rpx;
				}

				.iconfont {
					position: absolute;
					top: 0;
					left: 30rpx;
					font-size: 44rpx;
				}
			}
		}

		.headtop {
			width: 100%;
			background: linear-gradient(90deg, #f9f9ff, #d4e8ff);
			height: 300rpx;
			padding: 20rpx 40rpx 0;
			box-sizing: border-box;

			.left {
				.mess {
					height: 48rpx;
					line-height: 48rpx;
					text-align: center;

					view {
						font-size: 24rpx;
						color: #333333;
					}

					.dian {
						width: 8rpx;
						height: 8rpx;
						background: #5C88FA;
						display: block;
						border-radius: 50%;
						margin: 0 auto;
					}

					.active {
						font-size: 32rpx;
						color: #333333;
						font-weight: 700;
						margin-left: 0;
					}
				}

				.mess1 {
					margin-left: 20rpx;
				}
			}

			.right {
				width: 116rpx;
				height: 36rpx;
				line-height: 36rpx;
				text-align: center;
				background: #FFFFFF;
				border-radius: 24rpx;
				margin-top: 6rpx;

				image {
					width: 36rpx;
					height: 36rpx;
					margin-left: 10rpx;
					margin-right: 6rpx;
				}

				.name {
					font-size: 24rpx;
					color: #333333;
				}
			}

			.rightts {
				margin-right: 20rpx;
				
				.name{
					color: #5C88FA;
				}
			}

			.sousuo {
				width: 100%;
				box-sizing: border-box;
				position: relative;
				margin-top: 30rpx;

				input {
					width: 100%;
					height: 60rpx;
					line-height: 60rpx;
					background: #ffffff;
					border-radius: 30rpx;
					padding-left: 30rpx;
					color: #999999;
					box-sizing: border-box;
				}

				image {
					width: 72rpx;
					height: 40rpx;
					position: absolute;
					right: 10rpx;
					top: 10rpx;
					z-index: 10;
				}
			}
		}

		.content {
			width: 100%;
			padding: 0 40rpx;
			box-sizing: border-box;
			margin-top: -120rpx;
			padding-bottom: 40rpx;

			.list {
				width: 100%;
				background: #fff;
				border-radius: 20rpx;
				margin-bottom: 20rpx;
				padding: 26rpx;
				box-shadow: rgba(223, 230, 255, 0.67) 0px 0px 6px;

				.top {
					width: 100%;
					border-bottom: 1rpx solid #F1F1F1;
					padding-bottom: 20rpx;

					image {
						width: 72rpx;
						height: 72rpx;
						margin-right: 20rpx;
					}

					.title {
						font-size: 28rpx;
						color: #333333;
						margin-top: 22rpx;
						font-weight: 700;
					}

					.money {
						font-size: 28rpx;
						color: #666666;
						margin-top: 22rpx;
						margin-right: 8rpx;
						font-weight: 700;
					}
				}

				.center {
					width: 96%;
					margin: 0 auto;
					margin-top: 20rpx;
					padding-bottom: 20rpx;

					.desc {
						width: 70%;
						font-size: 24rpx;
						color: #333333;
						line-height: 36rpx;
					}

					.descid {
						width: 30%;
						font-size: 24rpx;
						color: #333333;
						line-height: 36rpx;
						text-align: right;
					}
				}

				.tongji {
					width: 100%;
					margin: 0 auto;
					background: #F6F8FF;
					border-radius: 16rpx;

					.liebiao {
						width: 50%;
						text-align: center;

						.money {
							margin-top: 20rpx;
							font-size: 40rpx;
							color: #333333;
							font-weight: 700;
						}

						.name {
							font-size: 24rpx;
							color: #333333;
							margin-bottom: 20rpx;
						}
					}
				}

				.bottom {
					width: 100%;
					margin: 0 auto;
					margin-top: 30rpx;
					text-align: center;

					.li {
						display: inline-block;
						padding-left: 32rpx;
						font-size: 28rpx;
						color: #368BF8;
						padding-right: 32rpx;
						margin-bottom: 4rpx;
						position: relative;
					}

					.li:nth-of-type(1) {
						padding-left: 0;
					}

					.li:nth-of-type(3) {
						padding-right: 0;
					}

					.xian {
						position: absolute;
						top: 8rpx;
						left: 0;
						width: 2rpx;
						height: 24rpx;
						background: #368BF8;
					}
				}
			}
		}

		.empty {
			width: 100%;
			margin: 200rpx auto 0;
			text-align: center;

			image {
				width: 390rpx;
				height: 340rpx;
			}

			text {
				display: block;
				margin-top: 60rpx;
				font-size: 24rpx;
				color: #666666;
			}
		}
	}
</style>